<template>
  <div class="qiaobi-wrap-container">
    <div class="qiaobi-box" @click="qiaobiClick">
      <div class="title" :style="getTitleBg(state)">
        {{ name }}
      </div>
      <div class="state" :style="getTextColor(state)">
        <span class="state-icon"></span>
        <span class="state-text">{{ state | stateFilter }}</span>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "ItemWrap",
  props: {
    name: {
      type: String,
      default: "",
    },
    state: { type: [Number, String] }, // 健康 0 ，1异常 ，2故障
    id: { type: String, default: "0" },
  },
  filters: {
    stateFilter(val) {
      if (val == 0) {
        return "健康";
      } else if (val == 1) {
        return "异常";
      } else if (val == 2) {
        return "严重";
      }
    },
  },
  methods: {
    getTitleBg(state) {
      return {
        "background-color":
          state == "0" || state == "3"
            ? "#24ba23"
            : state == "1"
            ? "#e08321"
            : state == "2"
            ? "#e21c23"
            : "#24ba23",
      };
    },
    getTextColor(state) {
      return {
        "background-color":
          state == "0" || state == "3"
            ? "#226b21"
            : state == "1"
            ? "#7b4d1d"
            : state == "2"
            ? "#641a1c"
            : "#1cbe21",
      };
    },
    qiaobiClick() {
      this.$emit("qiaobiClick", this.id);
    },
  },
};
</script>
<style scoped lang="less">
.qiaobi-wrap-container {
  position: relative;
  width: 0;
  height: 0;
  padding: 10px;
  box-sizing: border-box;
  .qiaobi-box {
    cursor: pointer;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    border: 1px solid #3099d1;
    background: rgba(48, 153, 209, 0.2);
    //margin: 8px;
  }
  .title {
    height: 36px;
    padding-left: 10px;
    font-size: 18px;
    line-height: 36px;
    color: #fff;
  }
  .state {
    height: 62px;
    padding: 0 10px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    span.state-icon {
      display: inline-block;
      width: 12px;
      height: 12px;
      border-radius: 50%;
      margin-right: 5px;
      background: #ffffff;
    }
    span.state-text {
      font-size: 16px;
      line-height: 62px;
      color: #ffffff;
    }
  }
}
</style>
